<template>
  <div>
    <FormPanel ref="form" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button size="mini" @click="closeDrawer">关 闭</el-button>
      <multiuse-button size="mini" type="primary" :click="dataHandle">保 存</multiuse-button>
    </div>
  </div>
</template>
<script>
import addCar from './addCar';
import { selectOne, editSave } from '@/api/dealerSale/salesPlan/PlanReportN1';

export default {
  props: ['rowData'], // 上个页面带入的值

  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom()
    };
  },
  components: {
    addCar
  },
  created() {
    this.init();
  },
  methods: {
    async init() {
      const res = await selectOne({ id: this.rowData.id });
      console.log(res)
      if (res.resultCode == 200) {
        this.formList.map(x => {
          x.initialValue = res.data[x.fieldName];
        });
      }
    },

    changeHandle(val) {
      this.saveData = val;
    },
    closeDrawer() {
      this.$emit('close');
    },

    async dataHandle() {
      this.$refs.form.SUBMIT_FORM();
      if (this.saveData) {
        let saveData = [
          {
            id: this.rowData.id,
            quantity: this.saveData.quantity
          }
        ];
        const res = await editSave(saveData);
        if (res.resultCode == 200) {
          this.$notify.success({ title: '提示信息', message: '操作成功' });
          this.$emit('close', false, 'refresh');
        }
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '车系名称',
          fieldName: 'seriesName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配置名称',
          fieldName: 'configName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '选装名称',
          fieldName: 'optionName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimColorName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '外饰',
          fieldName: 'colorName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '市场指导价',
          fieldName: 'oemDirectivePrice',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: 'N+1提报数量',
          fieldName: 'quantity',
          min: 0,
          max: 99999
        }
      ];
    }
  }
};
</script>
